package cn.lili.controller.permission;

import cn.lili.common.aop.annotation.DemoSite;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.permission.entity.dos.AdminUser;
import cn.lili.modules.permission.entity.dos.Audit;
import cn.lili.modules.permission.entity.vo.AgentVO;
import cn.lili.modules.permission.service.AdminUserService;
import cn.lili.modules.permission.service.AuditService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * create by yudan on 2022/2/10
 */
@RestController
@Api(tags = "代理商接口")
@RequestMapping("/manager/agent")
public class AgentController {

    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private AuditService auditService;


    @ApiOperation(value = "代理商分页列表")
    @GetMapping
    public ResultMessage<IPage<AgentVO>> getByPage(AgentVO agent, PageVO page) {
        return ResultUtil.data(adminUserService.getAgentPage(agent, page));
    }

    @ApiOperation(value = "审核申请")
    @PutMapping(value = "/audit")
    public ResultMessage<Object> audit(Audit audit) {
        auditService.audit(audit);
        return ResultUtil.success();
    }

    @ApiOperation(value = "修改会员基本信息")
    @PutMapping
    @DemoSite
    public ResultMessage<Object> update(@Valid AdminUser adminUser) {
        return ResultUtil.data(adminUserService.updateAdminUserRegion(adminUser));
    }

    @ApiOperation(value = "删除代理商")
    @ApiImplicitParam(name = "id", value = "代理商ID", required = true, allowMultiple = true, dataType = "String", paramType = "path")
    @DeleteMapping(value = "/delByIds/{id}")
    public ResultMessage<Object> delAllByIds(@NotNull(message = "代理商ID不能为空") @PathVariable("id") String id) {
        auditService.deleteByUserId(id,1);
        return ResultUtil.success();
    }

    @ApiOperation(value = "修改会员状态,开启关闭会员")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "代理商ID", required = true, dataType = "String", allowMultiple = true, paramType = "query"),
            @ApiImplicitParam(name = "disabled", required = true, dataType = "boolean", paramType = "query")
    })
    @PostMapping("/updateStatus")
    @DemoSite
    public ResultMessage<Object> updateStatus(@RequestParam String id, @RequestParam Boolean status) {
        adminUserService.updateStatus(id, status);
        return ResultUtil.success();
    }

}
